<template>
  <div>
    <el-form ref="form" :model="form" label-width="80px" :rules="rules">
      <el-form-item label="用户名" prop="mobile">
        <el-input v-model="form.mobile" />
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="form.password" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="save()">更新</el-button>
        <el-button @click="$router.back()">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getBasicInfo } from '@/api/user'
import { updataLoginInfro } from '@/api/employee'
export default {
  data() {
    return {
      form: {
        mobile: '',
        password: ''
      },
      rules: {
        mobile: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.loadInfro()
  },
  methods: {
    async loadInfro() {
      const { mobile } = await getBasicInfo(this.$route.params.id)
      this.form.mobile = mobile
    },
    async save() {
      // 校验表格
      await this.$refs.form.validate()
      // 调用接口
      await updataLoginInfro(this.$route.params.id, this.form)
      // 提示用户
      this.$message.success('保存成功')
      // 跳转页面
      this.$router.back()
    }
  }
}
</script>

<style lang="scss" scoped>
.el-form{
  width: 50%;
  margin-left: 120px;
  margin-top: 30px;
}
</style>
